//
//  CarSpecialView.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/9/21.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "CarSpecialView.h"

@interface CarSpecialView()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *array;

@end

@implementation CarSpecialView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ScreenWidth, 5000);

        [self loadUI];
    }
    
    return self;
}

- (void)loadUI{
    _array = @[@"不限",@"准新车",@"新车"];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 320+64, ScreenWidth, 44*3) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    
    cell.textLabel.text = _array[indexPath.row];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *str = _array[indexPath.row];
    [self.delegate sendSpecial:str];
    [self removeFromSuperview];
}


- (void)show{
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    __weak CarSpecialView *my = self;
    [UIView animateWithDuration:0.3 animations:^{
        my.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
